using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Sim3D_practicum.Physics;

namespace Sim3D_practicum.Components
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// <param name='position'>Position of the ramp</param>
    /// <param name='height'>Height of the ramp.</param>
    /// <param name='direction'>Horizontal direction of the ramp. Determines the ramp's horizontal length</param>
    /// </summary>
    public class Ramp : Microsoft.Xna.Framework.DrawableGameComponent
    {
        public ICollidableObject surface;
        static Texture2D art;
        Rectangle rect;
        public Ramp(Vector3 position, float height, Vector3 direction, Game game)
            : base(game)
        {
            Vector3 dir1 = new Vector3(-direction.X, height, -direction.Z);
            Vector3 dir2 = new Vector3(direction.Z * 10, 0, -direction.X * 10);
            surface = new Plain(dir1,dir2,position);
            float x = Math.Min(0, Math.Min(dir1.X, dir2.X));
            float z = Math.Min(0, Math.Min(dir1.Z, dir2.Z));
            float w = Math.Max(-x, Math.Max(dir1.X, dir2.X));
            float h = Math.Max(-z, Math.Max(dir1.Z, dir2.Z));
            x += position.X;
            z += position.Z;
            rect = new Rectangle(Calculator.mmToPixel(x), Calculator.mmToPixel(z), Calculator.mmToPixel(w), Calculator.mmToPixel(h));
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }
        protected override void LoadContent()
        {
            if (art == null)
                art = Game.Content.Load<Texture2D>("TableGreen");
            base.LoadContent();
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here

            base.Update(gameTime);
        }

        public void Draw(GameTime gameTime, SpriteBatch sprite)
        {
            sprite.Begin();
            sprite.Draw(art, rect, Color.Gray);
            sprite.End();
            base.Draw(gameTime);
        }
    }
}
